﻿using CodeStash.Addin.Core;
using CodeStash.Addin.ViewModels;
using CodeStash.Addin.Resources;

namespace CodeStash.Addin
{
    public class AddSnippetViewModelValidator : Validator
    {
        private AddSnippetViewModel vm;

        public AddSnippetViewModelValidator(AddSnippetViewModel vm)
        {
            this.vm = vm;
            this.EntityError = "AddSnippetViewModel has errors";
        }

        protected override void ValidateOverride()
        {
            if (vm.SelectedLanguage == null || vm.SelectedLanguage.LanguageId == 0)
                ValidationFailure("SelectedLanguage", Messages.SelectedLanguage);

            if (string.IsNullOrWhiteSpace(vm.Description))
                ValidationFailure("Description", Messages.MissingDescription);

            if (string.IsNullOrWhiteSpace(vm.Title))
                ValidationFailure("Title", Messages.MissingTitle);

            if (string.IsNullOrWhiteSpace(vm.Category))
            {
                ValidationFailure("Category", Messages.MissingCategory);
            }

            //if (vm.AddGroup)
            //{
            //    if (string.IsNullOrEmpty(vm.NewGroup))
            //        ValidationFailure("NewGroup", Messages.MissingNewGroup);
            //}
            //else
            //{
            //    if (vm.SelectedGroup == null || vm.SelectedGroup.GroupId == 0)
            //        ValidationFailure("SelectedGroup", Messages.MissingGroup);
            //}
        }
    }

}
